﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using System.Windows;
using FinPlusAssembler;
using FinPlusInterfaces;

namespace FinPlusCompView
{
    public partial class FinPlusColOnOffButton : FinPlusControl
    {
        [State(Test = true)]
        public override bool IsValid { get; set; }
        public event EventHandler<IPod> ColOnOff;

        //construct
        public FinPlusColOnOffButton(string name)
        {
            InitializeComponent();
            Tag = Id = name;
            bStart.Content = name;
            IsValid = true;
        }

        //common control interface
        public override void CmdExecute(IPod command)
        {
            try
            {
                CmdCapture(command);

                switch ((Cmds)Enum.Parse(typeof(Cmds), command.Name, true))
                {
                    case Cmds.ColOn:
                    case Cmds.ColOff: ColOnOffs(command); break;
                    default: throw new Exception(string.Format("cmd not recognised {0}", command.Name));
                }

            }
            catch (CmdExecuteException e)
            {
                IsValid = Level.Warning.Log(Id, Config, e.Message, e);
            }
        }

        //private
        private void ColOnOffs(IPod pod)
        {
            if (ColOnOff != null) 
                ColOnOff.Invoke(this, pod);
        }

        private enum Cmds { ColOn, ColOff }
    }
}
